const BASE_URL = 'http://192.168.10.130:8089/api';
// const BASE_URL = 'http://mail.rlhotel.cn/api/';
const request = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method,
			data: options.data || {},
			header:  {
				"token": uni.getStorageSync("token")
			}
		}).then(response => {
		 let data = response[1].data;
			if (data.status == 200) {
				uni.setStorageSync('token', data.token);
				uni.setStorageSync('permission', data.data.permissionName);
				resolve(data)
				uni.switchTab({
					url: '/pages/index/index'
				});
			} else if (data.status != 200) {
				uni.redirectTo({
					url: '/pages/user/login'
				})
				uni.$u.toast('请重新登录')
				// uni.switchTab({
				//     url: '/pages/car/car'
				// });
			} else {
				uni.redirectTo({
					url: '/pages/user/login'
				})
				uni.$u.toast('请重新登录')

			}
		}).catch(err => {
			reject(err)
		})
	})
}

export default request
